﻿@model  Model.PageRole
@{
    ViewBag.Title = "模型信息列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style>
        select
        {
            width: 90px;
        }
    </style>
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();
        var pageRole = '@Model.role';
        $(function () {
            InitList();
        });
        var opts = {
            rows: 15,
            height: 450,
            url: "/ModelConfig/GetList",
            para: { tableName: $("#txt_TableName").val(), dbName: encodeURI(UrlArray["dbName"]) },
            idField: "GUID",
            columns: [
                    { field: 'TableName', title: '名称', width: 33, sortable: true },
                    { field: 'TableDescription', title: '描述', width: 33, sortable: true },
                    { field: 'CreateTime', title: '创建时间', width: 8, align: 'center', sortable: true },
                    { field: 'TableType', title: '模型状态', width: 8, align: 'center' },
                    { field: 'IsRecord', title: '版本记录', width: 8, align: 'center' },
                    { field: 'GUID', title: '操作', width: 10, align: 'center', formatter: function (value, rowData, rowIndex) {
                        var a = "<select onchange=\"DoAction(this.options.selectedIndex,'" + value + "'," + rowData.Type + ")\"><option value=''>-请选择-</option>";

                        if (rowData.Type == "1") {
                            if (pageRole == '2')
                                return a + "<option>修改</option><option>删除</option></select>";
                            else
                                return "";
                        }
                        else {
                            if (pageRole == '2')
                                return a + "<option>修改</option><option>删除</option><option>复制模型</option><option>发送到实例</option><option>查看渐变维度</option><option>跟踪</option><option>查看模型数据</option><option>查看数据质量数据</option></select>";
                            else
                                return a + "<option>查看渐变维度</option><option>跟踪</option><option>查看模型数据</option><option>查看数据质量数据</option></select>";
                        }
                    }
                    }
                    ]
        };
        function InitList() {
            opts.para["tableName"] = $("#txt_TableName").val();
            opts.para["dbName"] = encodeURI(UrlArray["dbName"]);
            $("#DataGrid2").dg(opts);
        }
        function DoAction(i, v, t) {
            if (pageRole == '1') {
                i = i + 4;
            }
            switch (i) {
                case 1:
                    addData(v, t);
                    break;
                case 2:
                    DelData(v, t);
                    break;
                case 3:
                    window.location = "/ModelConfig/CopyModel?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 4:
                    window.location = "/ModelConfig/SendModel?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 5:
                    window.location = "/ModelConfig/ConfigRecordList?modelID=" + v + "&dbName=" + encodeURI(UrlArray["dbName"]);
                    break;
                case 6:
                    GetPath(v, 'model', 0);
                    InitList();
                    break;
                case 7:
                    showModalMany('Info', '/ModelConfig/GetModelData?modelID=' + v + '&dbName=' + encodeURI(UrlArray["dbName"]), '900', '400');
                    InitList();
                    break;
                case 8:
                    showModalMany('Info', '/DQConfig/Index?modelID=' + v + '&viewDQ=1&dbName=' + encodeURI(UrlArray["dbName"]), '800', '400');
                    InitList();
                    break;
            }
        }
        function ModelTableInfo(v, t) {
            showModalMany('Info', '/ODSConfig/TableInfo?modelID=' + v + '&tbName=' + t + '&dbName=' + encodeURI(UrlArray["dbName"]), '900', '480');
            InitList();
        }
        function btnSearch() {
            thisPageNum = 1;
            InitList();
        }
        function addData(id, t) {
            if (t == 1)
                window.location = "/ModelConfig/EditType?id=" + id + "&dbName=" + encodeURI(UrlArray["dbName"]);
            else if (t == 2)
                window.location = "/ModelConfig/End?modelID=" + id + "&dbName=" + encodeURI(UrlArray["dbName"]);
            else
                window.location = "/ModelConfig/Edit?modelID=" + id + "&dbName=" + encodeURI(UrlArray["dbName"]);
        }
        function DelData(v, t) {
            if (confirm("确定要删除吗？")) {
                $.post("/ModelConfig/Delete", { id: v, Type: t, dbName: encodeURI(UrlArray["dbName"]) }, function (result) {
                    if (result == "1") {
                        alert("操作成功。");
                    }
                    else if (result == "2")
                        alert("删除失败！模型分类下包含模型，请先删除模型分类下的模型。");
                    else
                        $("#msg").html(result);
                    InitList();
                });
            } else
                InitList();
        }
        function ViewList(id, n) {
            goto('/ModelConfig/ModelList?TypeID=' + id + '&TypeName=' + n + '&dbName=' + encodeURI(UrlArray["dbName"]));
        }
        function returnFun(v) {
            DoAction(v[0], v[1], 2);
        }
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                模型配置搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                模型名称：
                <input type="text" id="txt_TableName" style="width: 300px;" />
                <input type="button" value="搜索" class="button" onclick="btnSearch()" />
            </td>
        </tr>
    </table>
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                模型配置列表
            </td>
            <td align="right">
                @if (Model.role == 2)
                { 
                    <input type="button" value="新增模型" class="button" onclick="addData('',3);" />
                    <input type="button" value="新增模型标签" class="button" onclick="addData('',1);" />
                }
            </td>
        </tr>
    </table>
    <table id="DataGrid2" class="pagTable" cellpadding="0" cellspacing="0">
    </table>
    <div>
        <div id="Pagination" class="pagination">
        </div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
    <div id="msg">
    </div>
</div>
